﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public List<Com> coms;
        public Form1()
        {
            InitializeComponent();
            coms = new List<Com>();
        }
       
        private void button1_Click(object sender, EventArgs e)
        {
            Form2 fm = new Form2();
            fm.father = this;
            fm.Choice = 0;
            fm.ShowDialog();

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
        public  void Bind(List<Com> Coms)
        {
            ListViewItem item = null;
           lvshow.Items.Clear();
            foreach (Com co in Coms)
            {
                item = new ListViewItem();
                item.Text = co.Model;
                item.SubItems.Add(co.Band);
                item.SubItems.Add(co.Cpu);
                item.SubItems.Add(co.Memory);
                item.SubItems.Add(co.Disk);
                item.SubItems.Add(co.Screen);
                this.lvshow.Items.Add(item);
               
            }

        }
        private void show(List<Com> Coms)
        {
            foreach (Com co in Coms)
            {
                if (this.lvshow.SelectedItems[0].Text == co.Model)
                {

                    label4.Text = co.show()[0];
                    label17.Text = co.show()[7];
                    label18.Text = co.show()[8];
                    label5.Text = co.show()[1];
                    label6.Text = co.show()[2];
                    label10.Text = co.show()[3];
                    label11.Text = co.show()[4];
                    label12.Text = co.show()[5];
                    label16.Text = co.show()[6];
                }
             
            }
           
        }

        private void lvshow_SelectedIndexChanged(object sender, EventArgs e)
        {
            show(coms);
            //this.lvshow.SelectedItems.Clear();
        }

        private void button2_Click(object sender, EventArgs e)
        {
          
            Form2 fm = new Form2( lvshow.SelectedItems[0].Text);
            fm.father = this;
            fm.Choice = 1;
            fm.ShowDialog();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < coms.Count; i++)
            {
                if (coms[i].Model == lvshow.SelectedItems[0].Text)
                {
                    coms.Remove(coms[i]);
                    Bind(coms);
                }
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            string content = "";
            for (int i = 0; i < coms.Count; i++)
            {
                content = content + "\n" + coms[i].Type + " " + coms[i].Model + " " + coms[i].Band + " " + coms[i].Cpu + " " + coms[i].Memory + " " + coms[i].Disk + " " + coms[i].Screen;
               
            }
            FileStream myFs = new FileStream("F:\\com.txt", FileMode.Create);
            StreamWriter mySw = new StreamWriter(myFs, Encoding.Unicode);
            mySw.Write(content);
            mySw.Close();
            myFs.Close();
            MessageBox.Show("写入成功");

        }

        private void button5_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
